-- Roblox 交易参数抓包脚本 v1.0
-- 功能：拦截 SendRequest / AcceptTrade 参数 + 监听 UpdateTrade 物品变化

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Trade = ReplicatedStorage:WaitForChild("Trade")

-- ✅ 阶段 1：监听交易状态变更，拿到装备内容
Trade:WaitForChild("UpdateTrade").OnClientEvent:Connect(function(data)
    print("【🟡 UpdateTrade 事件捕获】")
    print("Locked:", data.Locked)
    print("LastOffer:", data.LastOffer)

    local function printItems(title, offer)
        if not offer then return end
        for i, item in ipairs(offer) do
            print(string.format("[%s] 第 %d 件：名称=%s，数量=%s，类型=%s", title, i, item[1], item[2], item[3]))
        end
    end

    if data.Player1 then
        printItems("我方物品", data.Player1.Offer)
        print("我方接受状态：", data.Player1.Accepted)
    end

    if data.Player2 then
        printItems("对方物品", data.Player2.Offer)
        print("对方接受状态：", data.Player2.Accepted)
    end

    print("===============")
end)

-- ✅ 阶段 2 & 3：拦截远程调用（SendRequest / AcceptTrade）
local mt = getrawmetatable(game)
setreadonly(mt, false)

local oldNamecall = mt.__namecall

mt.__namecall = function(self, ...)
    local method = getnamecallmethod()
    local args = {...}
    local remoteName = tostring(self)

    if remoteName == "SendRequest" and method == "InvokeServer" then
        warn("【🟢 SendRequest 发起交易捕获】")
        for i, arg in ipairs(args) do
            warn(string.format("参数[%d] = (%s)", i, typeof(arg)), arg)
        end
    elseif remoteName == "AcceptTrade" and method == "FireServer" then
        warn("【🟢 AcceptTrade 接受/确认 捕获】")
        for i, arg in ipairs(args) do
            warn(string.format("参数[%d] = (%s)", i, typeof(arg)), arg)
        end
    end

    return oldNamecall(self, unpack(args))
end

print("✅ [交易拦截器] 启动成功，请执行一次交易流程来抓包")
